package com.cykj.controller;

import com.cykj.bean.MessageBean;
import com.cykj.bean.Tblgood;
import com.cykj.service.GameMallService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/mall" , method = {RequestMethod.POST,RequestMethod.GET})
@Api(tags = "商城后台")
public class GameMallController {
    @Autowired
    private GameMallService gameMallService;
// 商品列表
    @RequestMapping("/findlist")
    @ApiOperation(value = "商城商品列表", notes = "商城商品列表" )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "size" ,value = "分页的大小",dataType = "integer"),
            @ApiImplicitParam(name = "page" ,value = "页码",dataType = "integer"),
            @ApiImplicitParam(name = "goodName" ,value = "查询的商品名字",dataType = "String"),
            @ApiImplicitParam(name = "type" ,value = "游戏类型",dataType = "integer")
    })
    public MessageBean findGoodList( Integer size,Integer page,String goodName,Integer type) {
        if(type == null){
            type = 0;
        }
        ArrayList<Tblgood> goodList = gameMallService.findGoodList(size, page,goodName,type);
        if(goodList.size() > 0){
            int total = gameMallService.cuontGoodList(goodName, type);
            //封装hashmap返回
            Map<String,Object> map = new HashMap<>();
            map.put("list",goodList);
            map.put("total",total);
            return MessageBean.success("",map);
        }
        return MessageBean.fail("查询为空");
    }
   @RequestMapping("/gametype")
   @ApiOperation(value = "游戏类型", notes = "游戏类型" )
    public MessageBean findGameType(){
        return MessageBean.success("",gameMallService.findGameTypeList());
   }
}
